package com.neusoft.actor.service.impl;

import com.neusoft.actor.client.ClientCareItemClient;
import com.neusoft.actor.client.MealClient;
import com.neusoft.actor.dao.ClientDao;
import com.neusoft.actor.po.CareItem;
import com.neusoft.actor.po.Client;
import com.neusoft.actor.po.ClientMealPreferences;
import com.neusoft.actor.service.ChatService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatServiceImpl implements ChatService {

    @Autowired
    public ClientDao clientDao;

    @Autowired
    public ClientCareItemClient clientCareItemClient;

    @Autowired
    public MealClient mealClient;


    @Tool(description = "美食")
    @Override
    public String test() {
        return "[\n" +
                "  { \"name\": \"白米饭\", \"category\": \"主食\", \"icon\": \"\uD83C\uDF5A\", \"description\": \"香甜软糯的白米饭\" },\n" +
                "  { \"name\": \"小米粥\", \"category\": \"主食\", \"icon\": \"\uD83E\uDD63\", \"description\": \"营养丰富的小米粥\" },\n" +
                "  { \"name\": \"豆浆\", \"category\": \"主食\", \"icon\": \"\uD83E\uDD5B\", \"description\": \"新鲜现磨豆浆\" },\n" +
                "  { \"name\": \"油条\", \"category\": \"点心\", \"icon\": \"\uD83E\uDD56\", \"description\": \"酥脆金黄的油条\" },\n" +
                "  { \"name\": \"包子\", \"category\": \"点心\", \"icon\": \"\uD83E\uDD5F\", \"description\": \"皮薄馅大的包子\" },\n" +
                "  { \"name\": \"鸡蛋\", \"category\": \"菜品\", \"icon\": \"\uD83E\uDD5A\", \"description\": \"营养丰富的鸡蛋\" },\n" +
                "  { \"name\": \"青菜\", \"category\": \"菜品\", \"icon\": \"\uD83E\uDD6C\", \"description\": \"新鲜时令青菜\" },\n" +
                "  { \"name\": \"西红柿鸡蛋\", \"category\": \"菜品\", \"icon\": \"\uD83C\uDF45\", \"description\": \"经典家常菜\" },\n" +
                "  { \"name\": \"红烧肉\", \"category\": \"菜品\", \"icon\": \"\uD83E\uDD69\", \"description\": \"香甜软糯红烧肉\" },\n" +
                "  { \"name\": \"糖醋里脊\", \"category\": \"菜品\", \"icon\": \"\uD83C\uDF56\", \"description\": \"酸甜可口糖醋里脊\" },\n" +
                "  { \"name\": \"宫保鸡丁\", \"category\": \"菜品\", \"icon\": \"\uD83C\uDF57\", \"description\": \"麻辣鲜香宫保鸡丁\" },\n" +
                "  { \"name\": \"清炒小白菜\", \"category\": \"菜品\", \"icon\": \"\uD83E\uDD6C\", \"description\": \"清淡爽口小白菜\" },\n" +
                "  { \"name\": \"冬瓜汤\", \"category\": \"汤类\", \"icon\": \"\uD83C\uDF72\", \"description\": \"清热解腻冬瓜汤\" },\n" +
                "  { \"name\": \"紫菜蛋花汤\", \"category\": \"汤类\", \"icon\": \"\uD83C\uDF72\", \"description\": \"营养美味蛋花汤\" },\n" +
                "  { \"name\": \"银耳莲子汤\", \"category\": \"汤类\", \"icon\": \"\uD83C\uDF72\", \"description\": \"滋补养颜莲子汤\" },\n" +
                "  { \"name\": \"馒头\", \"category\": \"主食\", \"icon\": \"\uD83C\uDF5E\", \"description\": \"松软香甜的馒头\" },\n" +
                "  { \"name\": \"花卷\", \"category\": \"主食\", \"icon\": \"\uD83E\uDD6F\", \"description\": \"层次丰富的花卷\" },\n" +
                "  { \"name\": \"面条\", \"category\": \"主食\", \"icon\": \"\uD83C\uDF5C\", \"description\": \"劲道爽滑的面条\" },\n" +
                "  { \"name\": \"水饺\", \"category\": \"点心\", \"icon\": \"\uD83E\uDD5F\", \"description\": \"皮薄馅大的水饺\" },\n" +
                "  { \"name\": \"馄饨\", \"category\": \"点心\", \"icon\": \"\uD83E\uDD5F\", \"description\": \"鲜美可口的馄饨\" }\n" +
                "]";
    }

    @Override
    @Tool(description = "查询所有老人")
    public String test2() {
        List<Client> list = clientDao.selectList(null);
        if (list == null || list.isEmpty()) {
            System.out.println("没有查询到任何数据！");
            return "没有查询到任何数据！";
        }

        StringBuilder result = new StringBuilder();
        for (Client client : list) {
            if (client == null || client.toString() == null || client.toString().isEmpty()) {
                System.out.println("Client 对象或其 toString 方法返回为空！");
                continue;
            }
            result.append(client.toString());
            result.append("\n");
        }

        if (result.toString().isEmpty()) {
            System.out.println("结果为空！");
            return "结果为空！";
        }

        return result.toString();
    }

    @Tool(description = "护理项目")
    @Override
    public String item() {
        List<CareItem> list = clientCareItemClient.getCareItemsByCondition("启用", null).getData();
        if (list == null || list.isEmpty()) {
            return "没有数据";
        }
        StringBuilder result = new StringBuilder();
        for (CareItem careItem : list) {
            if (careItem == null || careItem.toString() == null || careItem.toString().isEmpty()) {
                continue;
            }
            result.append(careItem.toString());
            result.append("\n");
        }
        if (result.toString().isEmpty()) {
            System.out.println("结果为空！");
            return "结果为空！";
        }

        return result.toString();
    }

    @Tool(description = "膳食配置")
    @Override
    public String preference() {
        List<ClientMealPreferences> list = mealClient.getAllClientMealPreferences().getData();
        if (list == null || list.isEmpty()) {
            return "没有数据";
        }
        StringBuilder result = new StringBuilder();
        for (ClientMealPreferences clientMealPreferences : list) {
            if (clientMealPreferences == null || clientMealPreferences.toString() == null || clientMealPreferences.toString().isEmpty()) {
                continue;
            }
            result.append(clientMealPreferences.toString());
            result.append("\n");
        }
        if (result.toString().isEmpty()) {
            System.out.println("结果为空！");
            return "结果为空！";
        }

        return result.toString();
    }
}
